package com.tacio.tarefas.controller;

import java.util.ArrayList;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tacio.tarefas.model.Tarefa;

@Controller
public class TarefasController {
	
	@RequestMapping("novaTarefa")
	public String form() {
		return "tarefa/formulario";
	}
	
	@RequestMapping("adicionarTarefa")
	public String adicionar(@Valid Tarefa tarefa, BindingResult result) {
		ArrayList<Tarefa> listaTarefas = new ArrayList<>();
		String retorno = "tarefa/adicionada";
		
		if (result.hasFieldErrors("descicao")) {
			retorno = "tarefa/formulario";
		}
		
		listaTarefas.add(tarefa);
		return retorno;
	}
	
}
